const ServiceFactory = require("../factory/ServiceFactory");

ServiceFactory.createPermissionInfoService().getPermissionTreeData()
    .then(result => {
        let arr = buildTreeData(result,0);
        console.log(JSON.stringify(arr));
    });

//递归生成树形结构
/**
 * 
 * @param {Array} list 
 * @param {number} parent_id 
 */
function buildTreeData(list, parent_id) {
    const arr = [];
    for (let item of list) {
        if (item.parent_id === parent_id) {
            item.children = buildTreeData(list, item.id);
            arr.push(item);
       }
    }
    return arr;
}